<template>
	<view class="content">
		<view class="block swiper-block">
			<Swiper1 :styleObj="{width: '100%',height: '400rpx',borderRadius: '0'}" :list="swiperList"></Swiper1>
		</view>
		<!-- <image mode="widthFix" :src="data.picUrl" class="top-bg"></image> -->
		<view class="detail-block">
			<view class="name">{{data.title}}</view>
			<view class="label-block">
				<view v-for="(item,index) in label" class="label-item">{{item}}</view>
			</view>
			<view class="position-block">
				<view class="position">
					<view class="iconfont icon-dingweixiao"></view>{{data.address?data.address:''}}
				</view>
				<view class="navigator-block" @click="openMap">
					<view class="iconfont icon-daohang"></view>
					<view class="label">到这去</view>
				</view>
			</view>
		</view>
		<view class="list-block">
			<template v-if="data.goods.length>0">
				<view v-for="(item,index) in data.goods" :key="item.id" class="list-item">
					<image mode="aspectFill" :src="item.picUrl" class="photo"></image>
					<view class="info-block">
						<view class="name">{{item.roomName}}</view>
						<view class="other">{{item.roomArea}}</view>
						<view class="price">￥{{item.price}}</view>
						<view class="btn1 btn" @click="advance(index)">立即预订</view>
					</view>
				</view>
			</template>
			<view v-else style="text-align: center;margin-top: 30rpx;">暂无数据</view>
		</view>
	</view>
</template>

<script>
	import {
		getListById
	} from '@/api/hotel.js';
	import {
		postReserve
	} from '@/api/food.js';
	export default {
		data() {
			return {
				label: ['收费停车场', '行李寄存', '近市中心', '近西关车站'],
				data: {
					// label: ['免费停车场', '行李寄存', '近市中心', '近西关车站'],
					goods: []
				},
				swiperList: [{
						id: 1,
						url: 'https://b2-q.mafengwo.net/s13/M00/28/D0/wKgEaVydzKOAEDx3AAPWkfowMBE25.jpeg?imageView2%2F2%2Fw%2F600%2Fh%2F600%2Fq%2F90'
					},
					{
						id: 2,
						url: 'https://p4-q.mafengwo.net/s13/M00/28/13/wKgEaVydzEiAS5nsAAKJfLFUJ8E06.jpeg?imageView2%2F2%2Fw%2F600%2Fh%2F600%2Fq%2F90'
					},
				],
			}
		},
		methods: {
			openMap() {
				uni.openLocation({
					longitude: this.data.longitude,
					latitude: this.data.latitude,
					name: this.data.title,
					address: this.data.address,
				})
			},
			getList() {
				let id = this.id
				getListById({
					id
				}).then((res) => {
					if (res.code == 1) {
						if (res.data != null) {
							this.data = res.data
							this.data.goods = res.data.roomList
							this.swiperList = res.data.viewAtlasList
							console.log(this.swiperList)
						}
					} else {
						console.log(res)
					}
				}).catch((res) => {
					console.log(res)
				})
			},
			//预定
			getAdvanceList(e) {
				postReserve({
					orderType: 3,
					tid: 0,
					sid: 0,
					hid: this.data.goods[e].id,
					count: 0,
					price: this.data.goods[e].price,
					useDate: ''
				}).then((res) => {
					console.log(res)
					if (res.code == 1) {
						uni.showToast({
							title: '预定成功',
							mask: true,
						})
					} else {
						uni.showToast({
							title: '加载失败',
							mask: true,
						})
					}
				}).catch((res) => {
					uni.hideLoading();
					uni.showToast({
						title: '加载失败',
						mask: true,
					})
				})
			},
			advance(e) {
				this.getAdvanceList(e)
			}
		},
		onLoad(e) {
			console.log(e)
			this.id = e.id
			this.getList()
		}
	}
</script>

<style lang="scss" scoped>
	.content {
		display: flex;
		flex-direction: column;
		background: #F4F4F4;
		min-height: 100vh;

		.top-bg {
			width: 100%;
			height: auto;
		}

		.detail-block {
			width: 100%;
			position: relative;
			border-radius: 5px;
			background: #F4F4F4;
			margin: 0 auto;
			margin-top: -60rpx;
			padding: 30rpx;
			padding-bottom: 0;
			display: flex;
			flex-direction: column;
			margin-bottom: 10rpx;

			.name {
				font-weight: bold;
				font-size: 42rpx;
				margin-bottom: 10rpx;
			}

			.label-block {
				display: flex;
				flex-direction: row;
				flex-wrap: wrap;
				margin-top: 10rpx;

				.label-item {
					font-size: 24rpx;
					color: $color-primary;
					background: rgba(64, 158, 255, .1);
					padding: 6rpx 8rpx;
					margin-right: 10rpx;
					border-radius: 6rpx;
					margin-bottom: 10rpx;
				}
			}

			.position-block {
				display: flex;
				flex-direction: row;
				align-items: center;
				font-size: 28rpx;
				padding: 10rpx 0;

				.position {
					display: flex;
					flex-grow: 1;
					align-items: center;

					.iconfont {
						margin-right: 8rpx;
					}
				}

				.navigator-block {
					flex-grow: 0;
					display: flex;
					flex-direction: column;
					justify-content: center;
					align-items: center;
					font-size: 24rpx;
					color: $color-primary;

					.iconfont {
						color: $color-primary;
						background: #efefef;
						font-size: 38rpx;
						border-radius: 50%;
					}
				}
			}
		}

		.list-block {
			display: flex;
			flex-direction: column;
			padding: 0 30rpx;

			.list-item {
				width: 100%;
				background: #fff;
				border-radius: 20rpx;
				padding: 20rpx;
				display: flex;
				flex-direction: row;
				margin-bottom: 20rpx;

				.photo {
					width: 180rpx;
					height: 180rpx;
					border-radius: 10rpx;
					margin-right: 20rpx;
				}

				.info-block {
					width: calc(100% - 200rpx);
					display: flex;
					flex-direction: column;
					position: relative;

					.name {
						font-weight: bold;
					}

					.other {
						font-size: 24rpx;
						color: $color-secondary-text;
						margin: 30rpx 0;
					}

					.price {
						color: $color-danger;
						font-weight: bold;
						font-size: 34rpx;
					}

					.btn {
						position: absolute;
						width: 180rpx;
						height: 60rpx;
						font-size: 28rpx;
						right: 0;
						bottom: 0;
					}
				}
			}
		}
	}
</style>